import { BaseService } from '../base.service'

import {getVerifyId} from "../auth/auth.service";
import Wrapper from "../util";

export class FilesService extends BaseService {
  static get entity () {
    return 'files'
  }
  static getDownloadLink(id, isShowNotification) {
    let verify_id = '?verify_id=' + getVerifyId();
    const wrapper = new Wrapper;
    return new Promise((resolve, reject) => {
      return this.request({auth: true}).get(`${this.entity}/getDownloadLink/${id}${verify_id}`).then(response => {
        wrapper.setWrapper(response, isShowNotification).then(() => {
          return resolve(response.data)
        }).catch(() => {
          return reject(response.data)
        })
      }).catch(error => {
        reject(console.log('getDownloadLink ' + this.entity, error))
      })
    })
  }

  static createWithoutAuth(data = window.required(), isShowNotification = true) {
    const wrapper = new Wrapper;
    return new Promise((resolve, reject) => {
      return this.request({auth: false}).post(`${this.entity}/storeWithoutAuth`, data).then(response => {
        wrapper.setWrapper(response, isShowNotification).then(() => {
          return resolve(response.data)
        }).catch(() => {
          return reject(response.data)
        })
      }).catch(error => {
        reject(console.log('createWithoutAuth ' + this.entity, error))
      })
    })
  }
}


